home *** CD-ROM | disk | FTP | other *** search
- package asp.netobjects.nfx.wizard;
-
- import asp.netobjects.nfx.util.ExceptionHandler;
- import com.sun.java.swing.BorderFactory;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JPanel;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.FontMetrics;
- import java.awt.Insets;
- import java.util.Vector;
-
- public class WizardPageView extends JPanel {
- private WizardPage dmWizardPage;
- private JPanel dmImagePanel;
- private JPanel dmPagePanel;
- private JPanel dmTextPanel;
- private JPanel dmContentPanel;
- private ImageCanvas dmTextCanvas;
- private int dmPagePanelLeftInset;
-
- public WizardPageView() {
- this.createControls();
- }
-
- public WizardPageView(WizardPage page) {
- this.dmWizardPage = page;
- this.createControls();
- }
-
- protected void createComponents() {
- }
-
- protected void layoutComponents() {
- }
-
- public void createControls() {
- ((Container)this).setLayout(new BorderLayout());
- this.createImagePanel();
- this.dmPagePanel = new JPanel();
- this.dmPagePanel.setLayout(new BorderLayout());
- this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, this.dmPagePanelLeftInset, 0, 0));
- ((Container)this).add("Center", this.dmPagePanel);
- this.createTextCanvas();
- this.dmContentPanel = new JPanel();
- this.dmContentPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
- this.dmPagePanel.add("Center", this.dmContentPanel);
- }
-
- private void createImagePanel() {
- if (this.getModel() != null) {
- if (this.getModel().getIcon() != null) {
- this.dmImagePanel = new JPanel();
- this.dmImagePanel.setLayout(new BorderLayout());
- this.dmImagePanel.setBorder(BorderFactory.createBevelBorder(1, Color.white, Color.gray));
- this.dmImagePanel.add(new JLabel(this.getModel().getIcon()));
- this.dmPagePanelLeftInset = 10;
- if (this.dmPagePanel != null) {
- this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, this.dmPagePanelLeftInset, 0, 0));
- }
-
- ((Container)this).add("West", this.dmImagePanel);
- } else if (this.dmImagePanel != null) {
- ((Container)this).remove(this.dmImagePanel);
- this.dmPagePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
- }
-
- }
- }
-
- private void createTextCanvas() {
- WizardPage model = null;
- if ((model = this.getModel()) != null) {
- if (this.dmTextCanvas != null) {
- ((Container)this).remove(this.dmTextCanvas);
- }
-
- if (model.getBulletText() != null || model.getInfoText() != null) {
- Insets insets = model.getWizard().getView().getInsets();
- int w = 470 - insets.left * 2 - 20 - this.dmPagePanelLeftInset;
- if (model.getIcon() != null) {
- w -= 70;
- }
-
- int h = 66;
- this.dmTextCanvas = new ImageCanvas(this, w, h);
- this.dmTextCanvas.repaint();
- this.dmPagePanel.add("North", this.dmTextCanvas);
- }
- }
- }
-
- public void validate() {
- }
-
- public WizardPage getWizardPage() {
- return this.dmWizardPage;
- }
-
- public WizardPage getModel() {
- return this.dmWizardPage;
- }
-
- public void setModel(WizardPage model) {
- this.dmWizardPage = model;
- this.createImagePanel();
- this.createTextCanvas();
- }
-
- public Wizard getWizard() {
- return this.dmWizardPage != null ? this.dmWizardPage.getWizard() : null;
- }
-
- public ExceptionHandler getExceptionHandler() {
- return this.dmWizardPage.getExceptionHandler();
- }
-
- public void setDirty(boolean set) {
- this.dmWizardPage.setDirty(set);
- }
-
- protected JPanel getContentPanel() {
- return this.dmContentPanel;
- }
-
- public boolean isValid() {
- return true;
- }
-
- private Vector toLines(String s, int width, int maxLines, FontMetrics fm) {
- Vector v = new Vector();
- int start = 0;
- int end = 0;
-
- for(int line = 1; (end = this.clipIndexOf(s, start, width, fm)) != -1; ++line) {
- v.addElement(s.substring(start, start + end));
- start = start + end + 1;
- if (line == maxLines) {
- break;
- }
- }
-
- return v;
- }
-
- private int clipIndexOf(String s, int idx, int width, FontMetrics fm) {
- int tot = 0;
- int start = 0;
- int end = 0;
- String str = s;
- if (idx > 0) {
- str = s.substring(idx);
- }
-
- int swidth = fm.charsWidth(str.toCharArray(), 0, str.length());
- if (swidth <= width) {
- return str.length() - 1;
- } else {
- while((end = str.indexOf(" ", start)) != -1) {
- String token = str.substring(start, end + 1);
- tot += fm.charsWidth(token.toCharArray(), 0, token.length());
- if (tot > width) {
- break;
- }
-
- start = end + 1;
- }
-
- return start - 1;
- }
- }
-
- // $FF: synthetic method
- static Vector access$0(WizardPageView $0, String $1, int $2, int $3, FontMetrics $4) {
- return $0.toLines($1, $2, $3, $4);
- }
- }
-